package com.sf.web.controller;

import com.sf.domain.Product;
import com.sf.qo.QueryObject;
import com.sf.service.IProductService;
import com.sf.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ProductController {

    @Autowired
    private IProductService productService;

    /**
     * /departmnet/list 请求
     * currentPage  当前页
     */
    @RequestMapping("/product/list")
    public String list(QueryObject queryObject, Model model){
        PageResult result = productService.query(queryObject);

        // 把数据放到model 中
        model.addAttribute("pageResult",result);
        // 跳转界面
        return "product/list";
    }


    @RequestMapping("/product/detail")
    public String detail(Model model,Long id){
        Product product = productService.get(id);
        model.addAttribute("product",product);
        return "product/detail";
    }

}
